package com.jd.service.impl;

import com.google.common.collect.Maps;
import com.jd.mapper.CategoryCustomMapper;
import com.jd.mapper.CategoryMapper;
import com.jd.pojo.Category;
import com.jd.service.CategoryService;
import com.jd.vo.CategoryVO;
import com.jd.vo.NewItemsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private CategoryCustomMapper categoryCustomMapper;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<Category> queryAllRootLevelCat() {
        Example example=new Example(Category.class);
        Example.Criteria userCriteria = example.createCriteria();
        userCriteria.andEqualTo("type","1");
        List<Category>  result=categoryMapper.selectByExample(example);
        return result;
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<CategoryVO> getSubCatList(Integer rootCatId) {
        return categoryCustomMapper.getSubCatList(rootCatId);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<NewItemsVO> getSixNewItemsLazy(Integer rootCatId) {
        Map<String,Object> map= Maps.newHashMap();
        map.put("rootCatId",rootCatId);
        return categoryCustomMapper.getSixNewItemsLazy(map);
    }
}
